include io.asm

stack segment stack
	dw 128 dup (?)
stack ends

;;======================================================================
data segment
	Head db "Vasilenko Anatoly. Group 111.$"
	Input db "Enter please number: $"
	Output db "Answer: $"
	Answer db 16 dup(' '), '$'
data ends
;;======================================================================

code segment 'code'
	assume ss:stack, ds:data, cs:code
start:
	mov ax,data
	mov ds,ax
	lea dx, Head
	outstr
	newline
	newline
	;;------------------------------------------------------------------
		lea dx, Input;
		outstr;
		
		xor ax, ax;
		xor dh, dh;
		L1:	inch dl;
			cmp dl, ' ';
			je break1;
			
			sub dl, '0';
			shl ax, 1;
			or ax, dx;
		jmp L1;
		break1:
		
		; Theró is a number on 'ax'
		
		mov cx, 16;
		L2: mov dl, 0;
			shr ax, 1;
			adc dl, '0';
			
			mov si, cx;
			mov Answer[si -1], dl;
			cmp ax, 0;
		loopne L2;
		
		lea dx, Output;
		outstr;
		lea dx, Answer[si -1];
		outstr;
	;;------------------------------------------------------------------

the_end:
	newline
	mov ah,8
	int 21h
    finish
code ends

;;======================================================================
end start 

;;======================================================================
